package services

import (
	"fmt"
	"gin_template/models"

	"github.com/go-basic/uuid"
	"go.uber.org/zap"
)

func InsertUser(userModel *models.User) string {
	//userModel.UserId = strconv.FormatInt(snowflake.GenId(), 10)
	userModel.UserId = uuid.New()
	if userId, err := userModel.InsertOne(); err != nil {
		return ""
	} else {
		return userId
	}
}

func DeleteUser(deleteModel *models.UserPrimary) error {
	var user = models.User{
		Id: deleteModel.Id,
	}
	if err := user.DeleteOne(); err != nil {
		return err
	} else {
		return nil
	}
}

func UpdateUser(updateModel *models.User) (*models.User, error) {
	if updateInfo, err := updateModel.UpdateOne(); err != nil {
		fmt.Println(err)
		return updateInfo, err
	} else {
		return updateInfo, nil
	}
}

func GetUser(userModel *models.UserPrimary) (*models.User, error) {
	var user = models.User{
		Id: userModel.Id,
	}
	if userInfo, err := user.FindOne(); err != nil {
		return nil, err
	} else {
		return userInfo, nil
	}
}

func QueryUserList(params *models.GetUserRequest) models.GetUserResponse {
	if res, err := models.FindUserList(params); err != nil {
		return res
	} else {
		zap.L().Info("result", zap.Any("res", res))
		return res
	}
}
